from common import exception
from common.LoggerFactory import Log
from service_sms.webhook.winxin import WinXinWebHook


class WebHookMessage:

    @staticmethod
    def send_win_xin_text(webhook_url, msg):
        """
        发送文本
        :param webhook_url: Webhook地址
        :param msg: 消息内容
        """
        Log.console().info(f"[微信]发送文本消息，MSG：{msg}")
        Log.file().debug(f"[微信]准备发送：{msg}")
        try:
            as_api = WinXinWebHook()
            as_api.send_text_msg(webhook_url, msg)
        except Exception as err:
            Log.error(f"[微信]文本消息发送失败，{err}")
            raise exception.ServiceException(f"[微信]消息发送失败，{err}")
        Log.file().debug(f"[微信]已发送，{msg}")

    @staticmethod
    def send_win_xin_markdown(webhook_url, markdown_text):
        """
        发送Markdown消息
        :param webhook_url: Webhook地址
        :param markdown_text: Markdown消息文本
        """
        Log.console().info(f"[微信]发送Markdown消息，MSG：{markdown_text}")
        Log.file().debug(f"[微信]准备发送：{markdown_text}")
        try:
            as_api = WinXinWebHook()
            as_api.send_markdown_msg(webhook_url, markdown_text)
        except Exception as err:
            Log.error(f"[微信]Markdown消息发送失败，{err}")
            raise exception.ServiceException(f"[微信]消息发送失败，{err}")
        Log.file().debug(f"[微信]已发送，{markdown_text}")
